﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Frame.Lib.Common;
using System.Text;
using Frame.Lib.Utilities;

namespace Frame.Web.Admin.Tools
{
    public partial class AppSetting : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Disp();
            }

        }

        private void Disp()
        {
            using (FileStream fs = new FileStream(Server.MapPath(GlobalVar.WebAppPath + "config/appsetting.config"), FileMode.Open))
            {

                using (StreamReader sr = new StreamReader(fs))
                {
                    txtSetting.Text = sr.ReadToEnd();
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (FileStream fs = new FileStream(Server.MapPath(GlobalVar.WebAppPath + "config/appsetting.config"), FileMode.Truncate))
                {
                    //byte[] byts = System.Text.Encoding.UTF8.GetBytes(txtConnectionString.Text.Trim());
                    //fs.Write(byts, 0, byts.Length);
                    //fs.Flush();
                    //fs.Close();

                    //有问题
                    using (StreamWriter sr = new StreamWriter(fs, Encoding.UTF8))
                    {
                        string str = txtSetting.Text.Trim().Replace("\r\n", "\n");
                        sr.Write(str);
                        sr.Flush();
                        fs.Flush();
                        JSUtil.Alert("保存成功");
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }
}